@extends('layout.master')

@section('title','操作积分管理')

@section('css')
    @parent
    <!-- Daterange picker plugins css -->
    <link href="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.css') }}" rel="stylesheet">
@endsection
@section('main')
    <div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel1">修改</h4>
                </div>
                <div class="modal-body">
                    <form class="floating-labels express">
                        <input id="id-edit" name="id" type="hidden" value="">
                        <fieldset style="border:0;">
                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="name" name="name"
                                       required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input1">操作名</label>
                            </div>
                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="number" name="number"
                                       required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input1">金币描述</label>
                            </div>
                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="frequency" name="frequency"
                                       required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input1">每日次数</label>
                            </div>
                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="content" name="content"
                                       required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input1">简介</label>
                            </div>
                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="add-number" name="add_number"
                                       required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input1">加金币数量</label>
                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                                                </button>
                                                {!! csrf_field() !!}
                                                <button type="submit" class="btn btn-success" id="btn-edit"><i
                                                            class="fa fa-check"></i> 保存
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="panel">
        <div class="panel-heading">操作积分管理</div>
        <div class="panel-wrapper collapse in" aria-expanded="true">
            <div class="panel-body">
                <div class="table-responsive">
                    <table id="example23" class="display nowrap" cellspacing="0" width="100%"
                           data-url="{{ url(request()->getUri()) }}">
                        <thead>
                        <tr>
                            <th>操作名</th>
                            <th>金币描述</th>
                            <th>每日次数</th>
                            <th>简介</th>
                            <th>加金币数量</th>
                            <th>修改</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('js')
    @parent
    <!-- Plugin JavaScript -->
    <script src="{{ asset('plugins/bower_components/moment/moment.js') }}"></script>
    <!-- Date range Plugin JavaScript -->
    <script src="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.js') }}"></script>
    <script src="{{ asset('js/myself.js') }}"></script>
    <script>
        $('.input-daterange-datepicker').daterangepicker({});
    </script>
    <script>
        function edit(sid) {
            $("#id-edit").val(sid);
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url: '/operationRecord/tasksInfo/' + sid,
                type: 'POST',
                success: function (data) {
                    $("#name").val(data.name);
                    $("#number").val(data.number);
                    $("#frequency").val(data.frequency);
                    $("#content").val(data.content);
                    $("#add-number").val(data.add_number);
                }
            })

        }



        $("#btn-edit").click(function (e) {
            e.preventDefault();
            var id = $('#id-edit').val();
            var name = $("#name").val();
            var number = $("#number").val();
            var frequency = $("#frequency").val();
            var content = $("#content").val();
            var add_number = $("#add-number").val();
            swal({
                    title: "",
                    text: "确定通过么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/operationRecord/tasksEdit/' + id,
                        data: {name:name, number: number, frequency: frequency, content:content, add_number:add_number},
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });

    </script>
@endsection